#ifndef APP_UART_H
#define APP_UART_H

#include "main.h"

#define         HEAD_FIRST                      0
#define         HEAD_SECOND                     1        
#define         PROTOCOL_VERSION                2
#define         FRAME_TYPE                      3
#define         LENGTH_HIGH                     4
#define         LENGTH_LOW                      5
#define         DATA_START                      6

#define         HEAT_BEAT_CMD                   0                               //心跳包
#define         PRODUCT_INFO_CMD                1                               //产品信息
#define         WORK_MODE_CMD                   2                               //查询MCU 设定的模块工作模式	
#define         WIFI_STATE_CMD                  3                               //wifi工作状态	
#define         WIFI_RESET_CMD                  4                               //重置wifi
#define         WIFI_MODE_CMD                   5                               //选择smartconfig/AP模式	
#define         DATA_QUERT_CMD                  6                               //命令下发
#define         STATE_UPLOAD_CMD                7                               //状态上报	 
#define         STATE_QUERY_CMD                 8                               //状态查询   
#define         UPDATE_START_CMD                0x0a                            //升级开始
#define         UPDATE_TRANS_CMD                0x0b                            //升级传输
#define         GET_ONLINE_TIME_CMD             0x0c                            //获取系统时间(格林威治时间)
#define         FACTORY_MODE_CMD                0x0d                            //进入产测模式    
#define         WIFI_TEST_CMD                   0x0e                            //wifi功能测试
#define         GET_LOCAL_TIME_CMD              0x1c                            //获取本地时间
#define         WEATHER_OPEN_CMD                0x20                            //打开天气          
#define         WEATHER_DATA_CMD                0x21                            //天气数据
#define         STATE_UPLOAD_SYN_CMD            0x22                            //状态上报（同步）
#define         STATE_UPLOAD_SYN_RECV_CMD       0x23                            //状态上报结果通知（同步）
#define         HEAT_BEAT_STOP                  0x25                            //关闭WIFI模组心跳

#define         DISTRIBUTION_NETWORD_CMD        0x2a                            //串口配网
#define         GET_WIFI_STATUS_CMD             0x2b                            //获取当前wifi联网状态
#define         WIFI_CONNECT_TEST_CMD           0x2c                            //wifi功能测试(连接指定路由)
#define         WIFI_RSSI_CMD                   0x24

#define         WIFI_EXTEND_CMD                 0x34
#define         DEV_NEW_FUNC_CMD                0x37

#define MCU_RX_VER              0x00                                            //模块发送帧协议版本号
#define MCU_TX_VER              0x03                                            //MCU 发送帧协议版本号(默认)
#define PROTOCOL_HEAD           0x07                                            //固定协议头长度
#define FRAME_FIRST             0x55                                            //帧头第一字节
#define FRAME_SECOND            0xaa                                            //帧头第二字节


#define WIFI_NAME           "tuya_mdev_test"   
#define WIFI_CODE           "12345678"   
#define TOKEN               "zzz"   
// #define WIFI_NAME           "iPetmon20220606"   
// #define WIFI_CODE           "ptm989809jdk"   
// #define TOKEN               "zzz"   
//{"s":"iPetmon20220606", "p":"ptm989809jdk", "t":"zzz"}
#define DISTRIBUTION_NETWORD_INFO   "{\"s\":\""WIFI_NAME"\", \"p\":\""WIFI_CODE"\", \"t\":\""TOKEN"\"}"

typedef enum {
    WIFI_STATE_CB,
    WIFI_RESET_CB,
    DPID_SET_CB,
    DPID_GET_CB,
    DPID_NOTIF_CB,
    OTA_NOTIF_CB,
    OTA_TRANS_CB,
    LMT_NOTIF_CB,
    FCTR_WFI_READY_CB,
    FCTR_WFI_CONN_CB,
    FCTR_WFI_RSI_CB,
    APP_UART_MAX_CB
} app_uart_cb_type_t;

typedef void (*app_uart_cb_t) (const unsigned char *, unsigned short);

void app_uart_init(void);
void app_uart_rx_task(void);
void app_uart_tx_wifi_reset(void);
void app_uart_tx_wifi_smart_config_reset(void);
void app_uart_tx_wifi_reset_noti(void);
void app_uart_tx_wifi_state_get(void);
void app_uart_tx_wifi_reset_noti(void);
void app_uart_tx_wifi_lmt_noti(void);
void app_uart_tx_dp_notify(const unsigned char *data, unsigned short length);
void app_uart_tx_dp_notify_record(const unsigned char *data, unsigned short length);
void app_uart_tx_ota_notif(void);
void app_uart_tx_ota_trans(void);
void app_uart_tx_scan_router(void);
void app_uart_tx_connect_router(unsigned char *data, unsigned short length);
void app_uart_tx_connect_rssi_get(void);

void app_uart_cb_register(app_uart_cb_type_t type, void (*cb) (const unsigned char *, unsigned short));

void app_uart_tx_wifi_distribution_network(void);    //串口配网

#endif